import type { EamCheckReport, EamCheckReportLine } from "@/pages/eam/checkReport/entity";
import apiClient from "../../apiClient";

export interface PageListReq {
  //状态
  status?: string;
  //点检结果
  checkResult?: string;
  //当前页码
  page: number;
  //每页数量
  pageSize: number;
}

export interface PageListRes {
  //总记录数
  total: number;
  //数据列表
  records: EamCheckReport[];
}

const pageList = (data: PageListReq): Promise<PageListRes> =>
  apiClient.post({
    url: "/eam/check/report/pageList",
    data
});
const getInfo = (id: React.Key): Promise<EamCheckReport> =>
  apiClient.get({
    url: `/eam/check/report/${id}`
});

const add = (data: EamCheckReport): Promise<EamCheckReport> =>
  apiClient.post({
    url: "/eam/check/report",
    data
});

const update = (data: EamCheckReport): Promise<EamCheckReport> =>
  apiClient.put({
    url: "/eam/check/report",
    data
});

const submit = (data: EamCheckReport): Promise<EamCheckReport> =>
  apiClient.post({
    url: "/eam/check/report/submit",
    data
});

const remove = (ids: React.Key[]): Promise<void> =>
  apiClient.delete({
    url: "/eam/check/report",
    params: {
    ids: ids.join(",")
  }
});

const updateStatus = (ids: React.Key[], status: string): Promise<void> =>
  apiClient.put({
    url: `/eam/check/report/status/${status}`,
    params: {
			ids: ids.join(","),
		},
});

const getreportLines = (id: React.Key): Promise<EamCheckReportLine[]> =>
  apiClient.post({
    url: "/eam/checkReport/line/list",
    data: {
      reportId: id
    }
  });

export const eamCheckReportService = {
  pageList,
  getInfo,
  add,
  update,
  submit,
  updateStatus,
  remove,
  getreportLines,
};

export default eamCheckReportService;